#!/bin/bash

# 启动应用服务
# Start Application Services

set -e

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"

cd "$PROJECT_ROOT"

echo "🚀 启动应用服务..."
echo "📦 Web (13000), API (8000), Crawler (8001), AI (8002)"
echo ""

# 检查数据库服务是否运行
if ! docker ps | grep -q "aipaper-postgresql"; then
    echo "⚠️  数据库服务未运行，请先启动数据库："
    echo "   ./scripts/start-databases.sh"
    exit 1
fi

# 启动应用容器
docker compose -f docker-compose.services.yml up -d

echo ""
echo "⏳ 等待服务启动..."
sleep 10

# 检查容器状态
docker compose -f docker-compose.services.yml ps

echo ""
echo "✅ 应用服务启动完成！"
echo ""
echo "🌐 服务地址："
echo "  前端 Web: http://localhost:13000"
echo "  API 网关: http://localhost:8000"
echo "  爬虫服务: http://localhost:8001"
echo "  AI 服务: http://localhost:8002"
echo ""
echo "💡 查看日志:"
echo "  所有服务: docker compose -f docker-compose.services.yml logs -f"
echo "  单个服务: docker compose -f docker-compose.services.yml logs -f web"
